import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;


/**
 * The MyFrame class initializes variables and runs the app
 * @author Daniel Barg, Ivan Petrov
 *
 */
public class MyFrame extends JFrame {
	//private Menu menu;
	private SetTime setTime;
	//private Settings settings;
	//private StopwatchPanel stopwatch;
	private TimerPanel timer;
	//private Times times;
	private JPanel cards;
	private LevelGenerator generate;
	private CardLayout layout;

	/**
	 * constructor
	 */
	public MyFrame(){
		try {
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		this.setSize(400,400);
		this.setLayout(new BoxLayout(this.getContentPane(),BoxLayout.PAGE_AXIS));
		this.setTitle("Timer App");
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
		generate=new LevelGenerator();
		cards=(JPanel) this.getContentPane();
		layout=new CardLayout();
		cards.setLayout(layout);
		// menu=new Menu(this);
		setTime=new SetTime(this);
		//stopwatch=new StopwatchPanel(this);
		// settings=new Settings(this);
		timer=new TimerPanel(this);
		// times=new Times(this);
		//  cards.add(menu,"menu");
		cards.add(setTime,"setTime");
		//  cards.add(getSettings(),"settings");
		//  cards.add(stopwatch,"stopwatch");
		cards.add(timer,"timer");
		//  cards.add(times,"times");
		layout.first(cards);
		this.setVisible(true);
		this.setResizable(false);
		this.setColors(Color.white);
	}
	/**
	 * main creats a new MyFrame
	 * @param args
	 */
	public static void main(String args[]){
		new MyFrame();
	}//end main
	/**
	 * displays the main menu
	 */
	public void mainMenu(){
		layout.show(cards, "menu");
	}//end mainMenu
	/**
	 * displays the set timer panel
	 * @param hoursSet - number of hours
	 * @param minutesSet - number of minutes
	 * @param secondsSet - number of seconds
	 */
	public void setTimer(int hoursSet, int minutesSet, int secondsSet) {
		setTime.init(hoursSet, minutesSet, secondsSet);
		layout.show(cards,"setTime");
	}//end setTimer
	/**
	 * goes to the setPreferences screen
	 */
	public void setPreferences(){
		layout.show(cards, "settings");
	}//end setPreferences

	/**
	 * goes to stopwatch mode
	 */
	public void stopwatch(){
		stopwatch.stopwatch();
		layout.show(cards, "stopwatch");
	}//end stopwatch

	/**
	 * goes to timer mode
	 */
	public void timer(){
		timer.timer(setTime.getTime()[0],setTime.getTime()[1],setTime.getTime()[2]);
		layout.show(cards, "timer");
	}//end Timer
	/**
	 * displays times
	 */
	public void seeTimes() {
		layout.show(cards, "times");
	}//end seeTimes
	/**
	 * sets the background color of the panels
	 * @param c - color to set background to
	 */
	public void setColors(Color c) {
		menu.setColors(c);
		setTime.setColors(c);
		stopwatch.setColors(c);
		getSettings().setColors(c);
		timer.setColors(c);
		times.setColors(c);
	}//end setColors

	/**
	 * retrieves the opposite color of the current one
	 * @param c - current color
	 * @return - opposite color
	 */
	public Color getOpposite(Color c){
		return new Color(255-c.getRed(), 255-c.getGreen(), 255-c.getBlue());
	}//end getOpposite

	/**
	 * sets the date the data was saved
	 * @param b - save or not save
	 */
	public void setSaveState(boolean b) {
		stopwatch.setSaveState(b);
	}//end setSaveState
	/**
	 * updates the displayed time
	 * @param theTimeNow - current time
	 * @param timesList - list of lap times
	 */
	public void updateList(String theTimeNow, ArrayList<String> timesList) {
		times.setText(theTimeNow, timesList);
	}//end updateList

	/**
	 * gets settings
	 * @return - Settings object
	 */
	public Settings getSettings() {
		return settings;
	}//end getSettings

	public void setComplexity(int hours, int minutes, int seconds) {
		int [] time={hours,minutes,seconds};
		generate.setComplexity(time);
	}
}//end MyFrame